import gpio
import os
import led

global light5
global light4
global light3
global light2
global light1
light5 = led.LED(5)  # 5
light4 = led.LED(9)  # 4
light3 = led.LED(14)  # 3
light2 = led.LED(10)  # 2
light1 = led.LED(13)  # 1
# 开关柱脚7
leds = [light1,light2,light3,light4,light5]

class Button:
    def __init__(self,pin_num):
        self.pin_num = pin_num
        gpio.gpio_init(pin_num)
        #找到柱脚
        func = gpio.query_func_value(pin_num,'gpio')
        gpio.set_func(pin_num,func)
        #设置初始为up
        pull_up = gpio.query_pull_value('up')
        gpio.set_pull(pin_num,pull_up)

    def off2up(self,cbfunc):
        #当由电频低到高时调用cbfunc
        gpio.set_dir(self.pin_num,gpio.dir_in)
        gpio.set_isr_mode(self.pin_num,gpio.rise_high)
        gpio.register_isr_func(self.pin_num,cbfunc,None)

# def cbfunc(arg):
#     for led in leds:
#         led.change()
#         os.sleep(100)
#         led.change()
#         os.sleep(100)

